package com.developer.platform.application.command;

import cn.hutool.core.bean.BeanUtil;
import com.developer.platform.application.command.cmd.GroupAdd;
import com.developer.platform.application.command.cmd.GroupUpdate;
import com.developer.platform.domain.Group;
import com.developer.platform.infrastructure.data.mapper.GroupMapper;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2020-12-29
 */
@Component
public class GroupCmdManager {

  private final GroupMapper groupMapper;

  public GroupCmdManager(
      GroupMapper groupMapper) {
    this.groupMapper = groupMapper;
  }

  public void save(GroupAdd groupAdd){
    Group group = new Group();
    BeanUtil.copyProperties(groupAdd, group);
    groupMapper.insert(group);
  }

  public void update(long id, GroupUpdate groupUpdate){
    Group group = new Group(id);
    BeanUtil.copyProperties(groupUpdate, group);
    groupMapper.updateById(group);
  }

  public void delete(long id){
    groupMapper.deleteById(id);
  }

}
